package com.yunyang.jczd.facade.fileexport.controller;


import com.yunyang.jczd.base.file.fileexport.dto.JczdExportRecordDTO;
import com.yunyang.jczd.base.file.fileexport.dto.SearchJczdExportRecordDTO;
import com.yunyang.jczd.business.response.PageResult;
import com.yunyang.jczd.business.response.Response;
import com.yunyang.jczd.business.response.ResponseUtils;
import com.yunyang.jczd.business.web.current.RequestContext;
import com.yunyang.jczd.facade.fileexport.service.IJczdExportRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Authorization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 导出记录表 前端控制器
 * </p>
 *
 * @author author
 * @since 2020-11-12
 */
@Api(tags = "文件导出记录 - API")
@RestController
@RequestMapping("/facade/export/record")
public class JczdExportRecordController {

    @Autowired
    IJczdExportRecordService exportRecordService;

    @Authorization(value = "")
    @ApiOperation(value = "分页查询导出记录")
    @PostMapping(value = "/pageMessageInfo")
    public Response<PageResult<JczdExportRecordDTO>> pageMessageInfo(@RequestBody SearchJczdExportRecordDTO param){
        param.setExportId(RequestContext.getAccountId());
        return ResponseUtils.success(exportRecordService.pageJczdExportRecord(param));
    }


    @ApiOperation(value = "更新导出状态")
    @PostMapping(value = "/updateState")
    public Response updateExportState(@RequestParam Long id, @RequestParam Integer state){
        if (!exportRecordService.updateExportState(id,state)){
            return ResponseUtils.fail("保存失败");
        }
        return ResponseUtils.success();
    }

    @ApiOperation(value = "保存")
    @PostMapping(value = "/saveExport")
    public Response<JczdExportRecordDTO> saveExport(@RequestParam Integer fileType, @RequestParam Integer exportType) {
        JczdExportRecordDTO bean = exportRecordService.saveExport(fileType, exportType);
        return ResponseUtils.success(bean);
    }

}
